package com.example.administrator.szb.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.util.Toasts;

import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.event.LoginStateChangeEvent;
import cn.jpush.im.android.api.model.UserInfo;

/**
 * Created by D N on 2017/11/29.
 */

public class UserLogoutEventReceiver extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        JMessageClient.registerEventReceiver(this);
    }

    @Override
    public void onDestroy() {
        JMessageClient.unRegisterEventReceiver(this);
        super.onDestroy();
    }

    public void onEvent(LoginStateChangeEvent event){
        LoginStateChangeEvent.Reason reason = event.getReason();//获取变更的原因
        UserInfo myInfo = event.getMyInfo();//获取当前被登出账号的信息
        switch (reason) {
            case user_password_change:
                //用户密码在服务器端被修改
                Toasts.show(this, "a", Toast.LENGTH_SHORT);
                break;
            case user_logout:
                //用户换设备登录
                Toasts.show(this, "h", Toast.LENGTH_SHORT);
                break;
            case user_deleted:
                //用户被删除
                Toasts.show(this, "b", Toast.LENGTH_SHORT);
                break;
        }
    }
}
